﻿// -----------------------------------------------------------------------
// <copyright file="ISystem.cs" company="">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

using BasicFrameworkDemo.IDAL;
using BasicFrameworkDemo.Utility;
using Castle.Facilities.AutoTx;
using Castle.Facilities.NHibernate;
using Castle.MicroKernel.Registration;

namespace BasicFrameworkDemo.IBLL
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    using BasicFrameworkDemo.Model;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public abstract class AppSystem
    {
        private static readonly NHibernateUtility NHibernateUtility = NHibernateUtility.GetInstance();
        private static readonly FluentNHibernateUtility FluentNHibernateUtility = FluentNHibernateUtility.GetInstance();
        private static readonly SystemErrors SystemErrors = SystemErrors.GetInstance();
        private static readonly Log4NetUtility Log4NetUtility = Log4NetUtility.GetInstance();
        private static readonly CastleUtility CastleUtility = CastleUtility.GetInstance();

         public abstract EchoResponse Echo();

        private static  bool _nHibernateFacilityAdded;

        public static InitializeResponse Initialize()
        {
            SystemErrors.Config();
            Log4NetUtility.Config();
            //NHibernateUtility.Config();
            //FluentNHibernateUtility.Config();
            CastleUtility.Config();

            if (_nHibernateFacilityAdded)
            {
                return new InitializeResponse();
            }

            CastleUtility.Container
                .AddFacility<AutoTxFacility>()
                .AddFacility<NHibernateFacility>();
            _nHibernateFacilityAdded = true;
            return new InitializeResponse();
        }
    }
}
